<template>
  <span>
    <!--显示提交/撤回按钮 && 有提交/撤回的权限 && 通话状态是已接听-->
    <a v-if="currentObj.QUALITY_GRADE && currentObj.QUALITY_GRADE !== '' || currentObj.TASK_ID && currentObj.TASK_ID !== '' || currentObj.randomTmp && currentObj.randomTmp.length > 0 || currentObj.TASK_ID && currentObj.TASK_ID.length > 0" @click="graded">{{$t('call.marked')}}</a>
    <a v-else-if="!currentObj.QC_SUBMIT" @click="submitCallSheetRecordToQC(currentObj.CALL_SHEET_ID, null)">{{$t('call.submitCallSheetRecordToQC')}}</a>
    <a v-else-if="currentObj.QC_SUBMIT" @click="revokeFromCallsSheetRecordQC(currentObj.CALL_SHEET_ID, null)">{{$t('call.revokeFromCallsSheetRecordQC')}}</a>
  </span>
</template>
<script>
  export default {
    name: 'submitRecord',
    data () {
      return {
      }
    },
    props: {
      currentObj: {
        type: Object,
        default: function () {
          return {}
        }
      }
    },
    methods: {
      graded () { // 已经评分
        this.$message.error(this.$t('call.yourCallMarked'))
      },
      submitCallSheetRecordToQC (callSheetId, confirmed) { // 提交录音
        let data = {}
        data._id = callSheetId
        data.confirm = confirmed
        this.$store.dispatch('submitCallSheetRecordToQC', data).then(res => {
          if (res && res.success) {
            if (res.notifyToClient) {
              this.$confirm(res.message, this.$t('public.tip'), {
                confirmButtonText: this.$t('public.confirm'),
                cancelButtonText: this.$t('public.cancel'),
                cancelButtonClass: 'primary_btn',
                confirmButtonClass: 'primary_btn',
                type: 'warning'
              }).then(() => {
                this.submitCallSheetRecordToQC(callSheetId, true)
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: this.$t('call.cancelSubmitCallSheetRecordToQC')
                })
              })
            } else {
              let routeArry = this.$route.path.split('/')
              let tabType = routeArry[3]
              let QC_SUBMIT = true
              this.$store.commit('call/SET_QC_SUBMIT', {tabType, QC_SUBMIT})
              this.$message.success(this.$t('call.audioSubmitSuccess'))
            }
          }
        })
      },
      revokeFromCallsSheetRecordQC (callSheetId, confirmed) { // 撤回录音
        let data = {}
        data._id = callSheetId
        data.confirm = confirmed
        this.$store.dispatch('revokeFromCallsSheetRecordQC', data).then(res => {
          if (!res.success) {
            this.$message.error(res.message)
          } else {
            if (res.notifyToClient) {
              this.$confirm(res.message, this.$t('public.tip'), {
                confirmButtonText: this.$t('public.confirm'),
                cancelButtonText: this.$t('public.cancel'),
                cancelButtonClass: 'primary_btn',
                confirmButtonClass: 'primary_btn',
                type: 'warning'
              }).then(() => {
                this.revokeFromCallsSheetRecordQC(callSheetId, true)
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: this.$t('call.cancelRevokeFromCallsSheetRecordQC')
                })
              })
            } else {
              let routeArry = this.$route.path.split('/')
              let tabType = routeArry[3]
              let QC_SUBMIT = false
              this.$store.commit('call/SET_QC_SUBMIT', {tabType, QC_SUBMIT})
              this.$message.success(res.message)
            }
          }
        })
      }
    }
  }
</script>
<style lang="stylus" scoped>
  a
    font-size: 12px
</style>
